package lc.字符串;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/24
 */
public class 剑指Offer58_翻转单词顺序 {

    public String reverseWords(String s) {
        String[] str = s.trim().split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = str.length - 1; i >= 0; i--) {

            if (str[i].length() != 0) {
                sb.append(str[i]);
                if (i != 0) {
                    sb.append(" ");
                }
            }
        }
        if (sb.length() == 0) return "";
        return sb.toString();
    }
}
